var t = require("../../../@babel/runtime/helpers/interopRequireDefault").default,
  e = require("../../../utils/http"),
  a = t(require("../../../components/u-charts/u-charts.min")),
  i = t(require("../../../utils/util")),
  n = new e.HTTP,
  d = {};
Page({
  data: {
    cWidth: 750,
    cHeight: 600,
    pixelRatio: 2,
    hiddens: !1,
    type: "",
    num: 1,
    unmonth: !0,
    slideWidth: "",
    slideLeft: 0,
    totalLength: "",
    slideShow: !1,
    slideRatio: "",
    dataList: [{
      text: "1"
    }, {
      text: "2"
    }, {
      text: "3"
    }, {
      text: "4"
    }, {
      text: "5"
    }, {
      text: "6"
    }, {
      text: "7"
    }, {
      text: "8"
    }, {
      text: "9"
    }, {
      text: "10"
    }, {
      text: "11"
    }, {
      text: "12"
    }],
    list: i.default.formatDates(new Date),
    funnel: !1,
    bm: 1
  },
  changeOil: function (t) {
    var e = this;
    if (wx.showLoading({
        title: "加载中"
      }), setTimeout((function () {
        wx.hideLoading()
      }), 200), 2 == t.target.dataset.num ? e.setData({
        unmonth: !1,
        hiddens: !0
      }) : e.setData({
        unmonth: !0,
        hiddens: !1
      }), e.setData({
        num: t.target.dataset.num,
        bm: 1
      }), 1 == e.data.unmonth)
      this.getServerData(), n.request({
        url: "https://www.qlsyyun.com:3000/trader/board",
        data: {
          arr: 9,
          zsy: e.data.user[0]
        }
      }).then((function (t) {
        e.setData({
          client: t.data[0]
        })
      }));
    else {
      var a = wx.getSystemInfoSync();
      this.setData({
          windowWidth: a.windowWidth
        }),
        this.getRatio(),
        n.request({
          url: "https://www.qlsyyun.com:3000/trader/board",
          data: {
            arr: 10,
            yf: e.data.list,
            zsy: e.data.user[0]
          }
        }).then((function (t) {
          0 == t.data.length ? e.setData({
            client: {
              jda: 0,
              jdb: 0,
              jdc: 0,
              jdd: 0
            }
          }) : e.setData({
            client: t.data[0]
          })
        }))
    }
  },
  getRatio: function () {
    if (this.data.dataList.length < 4)
      this.setData({
        slideShow: !1
      });
    else {
      var t = 173 * this.data.dataList.length,
        e = 80 / t * (750 / this.data.windowWidth),
        a = 750 / t * 160;
      this.setData({
        slideWidth: a / 2,
        totalLength: t,
        slideShow: !0,
        slideRatio: e
      })
    }
  },
  getleft: function (t) {
    this.setData({
      slideLeft: t.detail.scrollLeft * this.data.slideRatio
    })
  },
  navlist: function (t) {
    var e = this,
      a = t.currentTarget.dataset.title;
    e.setData({
        list: a
      }),
      n.request({
        url: "https://www.qlsyyun.com:3000/trader/board",
        data: {
          arr: 10,
          yf: e.data.list,
          zsy: e.data.user[0]
        }
      }).then((function (t) {
        0 == t.data.length ? e.setData({
          client: {
            jda: 0,
            jdb: 0,
            jdc: 0,
            jdd: 0
          }
        }) : e.setData({
          client: t.data[0]
        })
      }))
  },
  onReady: function () {
    var t = 1 * wx.getSystemInfoSync().windowWidth,
      e = 500 / 750 * wx.getSystemInfoSync().windowWidth,
      a = wx.getSystemInfoSync().pixelRatio,
      i = wx.getStorageSync("user");
    this.setData({
        cWidth: t,
        cHeight: e,
        pixelRatio: a,
        user: i
      }),
      this.getServerData()
  },
  getServerData: function () {
    var t = this,
      e = this;
    n.request({
      url: "https://www.qlsyyun.com:3000/trader/board",
      data: {
        arr: 8,
        zsy: e.data.user[0]
      }
    }).then((function (a) {
      if (0 == a.data.length)
        wx.showToast({
          title: "暂无漏斗数据",
          icon: "none"
        }), e.setData({
          unmonth: !1
        });
      else {
        e.setData({
          hopper: a.data[0]
        });
        var i = {
          series: [{
            data: [{
              name: "有效客户",
              value: e.data.hopper.bbkh,
              labelText: e.data.hopper.bbkh
            }, {
              name: "初步接触",
              value: e.data.hopper.cbkh,
              labelText: e.data.hopper.cbkh
            }, {
              name: "持续跟进",
              value: e.data.hopper.cxkh,
              labelText: e.data.hopper.cxkh
            }, {
              name: "核名办证",
              value: e.data.hopper.hmkh,
              labelText: e.data.hopper.hmkh
            }, {
              name: "产税",
              value: e.data.hopper.cskh,
              labelText: e.data.hopper.cskh
            }]
          }]
        };
        t.drawCharts("SXHyIJPntMlUPAmpQIBiHCeHlVHuEudD", i)
      }
    }))
  },
  drawCharts: function (t, e) {
    var i = this;
    wx.createSelectorQuery().in(this).select("#" + t).fields({
      node: !0,
      size: !0
    }).exec((function (n) {
      if (n[0]) {
        var s = n[0].node,
          r = s.getContext("2d");
        s.width = n[0].width * i.data.pixelRatio,
          s.height = n[0].height * i.data.pixelRatio,
          d[t] = new a.default({
            type: "funnel",
            context: r,
            width: i.data.cWidth * i.data.pixelRatio,
            height: i.data.cHeight * i.data.pixelRatio,
            series: e.series,
            pixelRatio: i.data.pixelRatio,
            animation: !0,
            background: "#FFFFFF",
            color: ["#D46973", "#EACE6D", "#6DBFF0", "#57A968", "#678AC0"],
            legend: {
              position: "bottom",
              float: "bottom",
              lineHeight: "20"
            },
            extra: {
              funnel: {
                borderWidth: 1
              }
            }
          })
      } else
        console.error("[uCharts]: 未获取到 context")
    }))
  },
  tap: function (t) {
    d[t.target.id].touchLegend(t),
      d[t.target.id].showToolTip(t)
  },
  onLoad: function () {
    var t = this,
      e = wx.getStorageSync("user");
    n.request({
      url: "https://www.qlsyyun.com:3000/trader/board",
      data: {
        arr: 9,
        zsy: e[0]
      }
    }).then((function (e) {
      t.setData({
        client: e.data[0]
      })
    }))
  }
});